/*
 * Copyright 2011 Clean GWT
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */
package com.cleangwt.user.client.activity;

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;

/**
 * The {@link Activity} is aware of {@link ActivityManager} can forward to and retrieve reference of
 * other activities that are also managed by the same {@link ActivityManager} .
 * 
 * @author Jess
 * @version 1.0
 * @since 1.0
 */
public class ForwardableActivity extends Composite implements Activity {

  private ActivityManager manager;

  /**
   * Just fires an {@link ForwardEvent} with the given index to ask activity manage to set the
   * activity of index to be active.
   * 
   * @param index the index
   */
  public void forward(int index) {
    manager.setActive(index);
  }

  /**
   * Gets the activity of index.
   * 
   * @param index the index
   * @return the activity of index
   */
  public <T extends Widget> T getActivity(int index) {
    return manager.getActivity(index);
  }

  @Override
  public void onActive(int relatedIndex) {
  }

  @Override
  public void onInactive() {
  }

  /**
   * Sets the {@link ActivityManager}.
   * 
   * @param manager the {@link ActivityManager}
   */
  void setActivityManager(ActivityManager manager) {
    this.manager = manager;
  }

}
